package cn.jjxx.modules.workflow.service.impl;

import java.util.ArrayList;
import java.util.List;

import cn.jjxx.core.common.service.impl.CommonServiceImpl;
import cn.jjxx.core.query.wrapper.EntityWrapper;
import cn.jjxx.core.utils.StringUtils;
import cn.jjxx.modules.workflow.mapper.ActMenuOrgMapper;
import cn.jjxx.modules.workflow.entity.ActMenuOrg;
import cn.jjxx.modules.workflow.service.IActMenuOrgService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**   
 * @Title: 模型菜单组织
 * @Description: 模型菜单组织
 * @author zcg
 * @date 2018-03-18 22:01:17
 * @version V1.0   
 *
 */
@Transactional
@Service("actMenuOrgService")
public class ActMenuOrgServiceImpl  extends CommonServiceImpl<ActMenuOrgMapper,ActMenuOrg> implements  IActMenuOrgService {

	@Override
	public boolean saveOrUpdate(String modelKey, String menuId, String[] orgIds) {
		List<ActMenuOrg> list = new ArrayList<ActMenuOrg>();
		if(StringUtils.isNotEmpty(modelKey)&&StringUtils.isNotEmpty(menuId)){
			for(String str:orgIds){
				ActMenuOrg amo = new ActMenuOrg();
				amo.setMenuId(menuId);
				amo.setModelKey(modelKey);
				amo.setOrgId(str);
				list.add(amo);
			}
			//TODO 根据菜单Id和模型key,删除原有的数据
			EntityWrapper<ActMenuOrg> wrapper = new EntityWrapper<ActMenuOrg>();
			wrapper.eq("model_key", modelKey);
			wrapper.eq("menu_id", menuId);
			super.delete(wrapper);
			if(list.size()>0){
		        //TODO 保存数据
				super.insertBatch(list);
			}
			return true;
		}else{
			return false;
		}
	}

	
}
